/**
 * createRouter 这个为创建路由的方法
 * createWebHashHistory 这个就是vue2中路由的模式，
 *                      这里的是hash模式，这个还可以是createWebHistory等
 * RouteRecordRaw 这个为要添加的路由记录，也可以说是routes的ts类型
 */
import {createRouter, createWebHashHistory} from "vue-router";
import NProgress from "nprogress";
import {routes} from "~/router/routes";

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: "/login",
            component: () => import("~/views/login/index.vue"),
            meta: {title: "登录"},
        },
        {
            path: "/",
            redirect: "/home",
            component: () => import("~/layouts/Layout.vue"),
            children: [
                ...routes,
                {
                    path: "/home",
                    component: () => import("@/views/Home.vue"),
                    meta: {title: "首页"},
                },{
                    path: "/system/company-list",
                    component: () => import("@/views/system/company/List.vue"),
                    meta: { title: "公司列表" },
                }, {
                    path: "/system/company",
                    component: () => import("@/views/system/company/UserCompany.vue"),
                    meta: { title: "公司管理" },
                }, {
                    path: "/system/org",
                    component: () => import("@/views/system/org/List.vue"),
                    meta: { title: "组织机构" },
                }, {
                    path: "/system/role",
                    component: () => import("@/views/system/role/List.vue"),
                    meta: { title: "角色" },
                }, {
                    path: "/system/user",
                    component: () => import("@/views/system/user/List.vue"),
                    meta: { title: "系统用户" },
                }, {
                    path: "/system/article",
                    component: () => import("~/views/system/article/List.vue"),
                    meta: { title: "文章管理" },
                }, {
                    path: "/system/user-info",
                    component: () => import("~/views/system/user/UserInfo.vue"),
                    meta: { title: "个人中心" },
                }, {
                    path: "/system/menu",
                    component: () => import("~/views/system/role/List.vue"),
                    meta: { title: "角色" },
                }, {
                    path: "/system/dictionary",
                    component: () => import("~/views/system/dictionary/List.vue"),
                    meta: { title: "字典" },
                }, {
                    path: "/system/message",
                    component: () => import("~/views/system/message/List.vue"),
                    meta: { title: "消息" },
                }, {
                    path: "/system/log",
                    component: () => import("~/views/system/log/Index.vue"),
                    meta: { title: "日志" },
                }, {
                    path: "/system/gen-table",
                    component: () => import("~/views/system/gen/List.vue"),
                    meta: { title: "代码生成" },
                }, {
                    path: "/wechat/user",
                    component: () => import("~/views/system/wechat/List.vue"),
                    meta: { title: "微信用户" },
                }
            ],
        },
    ],
});


router.beforeEach((to, from, next) => {
    NProgress.start(); // 进度条开始
    next();
    if (to.meta.title) {
        // @ts-ignore
        document.title = to.meta.title;
    }
});

router.afterEach(() => {
    NProgress.done(); // 进度条结束
});

export default router;
